<template>
    <div class="container">
        <h3>数据发送</h3>
            <el-row style="margin-top:20px;">
                <el-col :span="7">
                    <el-input placeholder="请输入关键词" v-model.trim="searchName" style="width:300px;">
                        <i slot="prefix" class="el-input__icon el-icon-search" ></i>

                        <el-button slot="append" @click="handleSearch">搜索</el-button>
                    </el-input>
                </el-col>
<el-button style="float:right; margin-right: 10px" @click="download">导出数据</el-button>
                <router-link to="/indent/send"><el-button type="primary" v-if="added" style="float:right; margin-right: 10px">新建发送</el-button></router-link>

            </el-row>

            <el-table
                :data="tableData"
                border
                style="margin-top:20px;"
                ref="multipleTable"
                header-cell-class-name="table-header"
            >
                <el-table-column prop="createTime" sortable label="发送时间"></el-table-column>
                <el-table-column prop="materialType" sortable label="产品分类"></el-table-column>
				<el-table-column prop="inventoryType" sortable label="产品大类"></el-table-column>
                <el-table-column prop="breedName" sortable label="名称"></el-table-column>
                <el-table-column prop="batch" sortable label="包装批号"></el-table-column>
                <el-table-column prop="loadingQuantity" sortable label="装量"></el-table-column>
                <el-table-column prop="clientName" sortable label="客户"></el-table-column>
                <el-table-column prop="sendNum" sortable label="数量">
                    <template slot-scope="scope">
                    {{scope.row.sendNum}}袋
                    </template>
                </el-table-column>
                <el-table-column prop="userName" sortable label="操作人"></el-table-column>
            </el-table>
            <el-pagination layout="total, prev, pager, next, jumper" :page-size="pagesize" :current-page.sync="currentPage" :total="total"  @current-change="handleCurrentChange" style="margin-top:20px"></el-pagination>

    </div>
</template>

<script>
	import axios from 'axios'
    import {order_findByList,send_export} from "@/request/api"
    import {CodeToText} from 'element-china-area-data'
    export default {
        data() {
            return {
                total:0,
                currentPage:1,
                pagesize:10,
                searchName: '',
                tableData: [],
                form: {},
                idx: -1,
                id: -1,
                boxCode:'',
                boxCode1:'',
                del:true,
                added:true,
                edit:true,
                action:'',
            };
        },
        created(){

        },
        mounted(){
            this.init()
        },
        methods: {
			download(){

				  axios({
				         method: 'GET',
				         url: '/order/out',

				         responseType: 'blob'
				     }).then(res=>{
				        //  console.log(res)
				         // let blob = new Blob([res.data], {type: "application/vnd.ms-excel"});
				         // let url = window.URL.createObjectURL(blob);
				         // window.location.href = url;
						   this.downloadFile(res, '数据.xls')

				     }).catch(err=>{
				         // console.log(err)
				     })

			},
           downloadFile(res, fileName) {
                   let blob = new Blob([res.data]);
                   if (!fileName) {
                     fileName = res.headers['content-disposition'].split('filename=').pop();
                   }
                   if ('msSaveOrOpenBlob' in navigator) {
                     window.navigator.msSaveOrOpenBlob(blob, fileName);
                   } else {
                     const elink = document.createElement('a');
                     elink.download = fileName;
                     elink.style.display = 'none';
                     elink.href = URL.createObjectURL(blob);
                     document.body.appendChild(elink);
                     elink.click();
                     URL.revokeObjectURL(elink.href);
                     document.body.removeChild(elink);
                   }
           },
            handleCurrentChange(val){
                this.currentPage = val
                this.init()
            },
            init(){
               order_findByList({
                   page:this.currentPage,
                   query:this.searchName
                }).then((res)=>{
                  this.tableData = res.rows;
                  this.total = res.total
                })
            },
            //搜索
            handleSearch(){
                this.currentPage = 1
                this.init()
            },
            //跳转编辑页面




        }
    }
</script>

<style scoped lang="less">
/deep/.upload-daoru{
    background: #eee;
    .el-upload{
        border: none;
        width: auto;
        height: auto;
        border-radius: 0;
        float: right;
        margin-right: 10px
    }
}
.el-table{ margin-top: 20px;}
 .el-pagination{
    text-align: center;
}
.el-pagination{
    text-align: center;
}
.el-col{
    margin-bottom:0;
}
</style>
